<?php

namespace apiend\controllers;

use Yii;
use apiend\components\Controller;
use apiend\models\ThirdPartyAuthForm;
use apiend\models\ThirdPartyQQForm;

/**
 * 第三方相关接口
 * ThirdPartyController
 */
class ThirdPartyController extends Controller {

    /**
     * Declares the allowed HTTP verbs.
     * Please refer to [[VerbFilter::actions]] on how to declare the allowed verbs.
     * @return array the allowed HTTP verbs.
     */
    protected function verbs() {
        return [
            '*' => ['POST']
        ];
    }

    /**
     * Declares the allowed HTTP verbs.
     * Please refer to [[VerbFilter::actions]] on how to declare the allowed verbs.
     * @return array the allowed HTTP verbs.
     */
    protected function rules() {
        return [
            [
                'actions' => ['connect', 'qq'],
                'allow' => true,
            ],
        ];
    }

    /**
     * 第三方登录
     * @return mixed
     */
    public function actionConnect() {
        $model = new ThirdPartyAuthForm();
        if (!$model->load(Yii::$app->request->post(), '')) {
            parent::error('请输入帐号和密码信息');
        }
        $model->token = $this->token;
        return $model->connect();
    }

    /**
     * qq第三方登录
     * @return mixed
     */
    public function actionQq() {
        $model = new ThirdPartyQQForm();
        if (!$model->load(Yii::$app->request->post(), '')) {
            parent::error('请输入帐号和密码信息');
        }
        $model->token = $this->token;
        return $model->connect();
    }

}
